package com.caojing.haolemai.ui.category.categoryadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.caojing.haolemai.R;
import com.caojing.haolemai.bean.categorybean.CategoryResultsBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by My on 2016/10/18.
 */
public class CategoryLeftAdapter extends BaseAdapter {

    private Context mContext;
    private List<CategoryResultsBean> categoryResultsBeanList;

    public CategoryLeftAdapter(Context context, List<CategoryResultsBean> list) {
        //Log.i("TAG","CategoryLeftAdapter----->"+list.toString());
        this.mContext = context;
        this.categoryResultsBeanList = list;

    }

    @Override
    public int getCount() {
        return categoryResultsBeanList != null ? categoryResultsBeanList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return categoryResultsBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.fragment_category_left_list_item, parent, false);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        CategoryResultsBean categoryResultsBean = categoryResultsBeanList.get(position);
        String virtualName = categoryResultsBean.getVirtualName();
        viewHolder.categoryLeftBtn.setText(virtualName);


        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.category_left_btn)
        TextView categoryLeftBtn;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
